home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / gfx / conv / CreateIndex.lha / CreateIndex.isrx < prev    next >
Text File  |  1999-01-21  |  8KB  |  290 lines

  1. /* ImageStudio ARexx script **************************************/
  2. /* generate HTML thumbnail image index files */
  3.  
  4. /* V1.0 2 Nov 97 by James Perrin */
  5. /* V2.0 19 Nov 97 added ability to update an index if new images */
  6. /*      have been added to the directory */
  7. /* V2.1 24 May 98 added skipping of files unable to load eg progressive jpegs */
  8. /* V2.1D 25 May 98 added thumbnail dimension gernation, split development into 
  9. two scripts */
  10. /* V3.0 25 June 98added max table rows => multiple HTML file generation */
  11. /* V3.1 20 Jan 99 add constant for file args. Second public release */ 
  12.  
  13. /* Allow commands to return results */
  14. options results
  15.  
  16. /* On error, goto ERROR:. Comment out this line if you wish to */
  17. /* perform your own error checking. */
  18.  
  19. signal on error
  20.  
  21. /* BEGIN PROGRAM *************************************************/
  22.  
  23. /* PROGRAM CONSTANTS - change these values to suit */
  24.  
  25. HTMLFile='Index'                /* What to call the html file, Oh Yes */
  26. SquareSize=100                    /* Size of square into which to fit pic */
  27. TNFormat='PNG'                    /* Thumbnail file format */
  28. TNArgs='INTERLACE=ADAM7'/* Thumbnail file format arguments */
  29. TNExten='png'                        /* Thumnail file extension */
  30. TNPrefix='TN'                        /* Thumbnail prefix */
  31. TableColumns=5                    /* No. of pics per row */
  32. TableRows=10                        /* No. of rows in table in each index file */
  33. TableBorder=1                        /* Size of table borders, in pixels */
  34.  
  35. FilePattern='~('HTMLFile'#?.html|'TN'#?)' /* only change if you understand arexx */
  36.  
  37. /* set program variables */
  38. nofile=0    /* flag that image can't be loaded */
  39.  
  40. /* get them files */
  41.  
  42. REQUEST_MULTIFILE TITLE '"Choose source files..."' PATTERN FilePattern STEM srcfiles.
  43.  
  44. /* Open html file and write basic info */
  45.  
  46. FILE_SPLIT FILE '"'srcfiles.files.0'"' STEM getpath.
  47.  
  48. /* program counters */
  49. ColumnCount=1
  50. RowCount=1
  51. FileCount=1
  52.  
  53. /* <<<<<<<< Process each file >>>>>>>> */
  54. do l = 0 to (srcfiles.files.count - 1)
  55.     
  56.     /* if start of table create new file */
  57.     if ColumnCount=1 & RowCount=1 then
  58.     do
  59.         if FileCount=1 then
  60.             WriteFile=HTMLFile'.html'
  61.         else
  62.         do
  63.             drop WritePathFile
  64.             WriteFile=HTMLFile||FileCount'.html'
  65.         end
  66.         
  67.         FILE_JOIN PATHPART '"'getpath.pathpart'"' FILEPART WriteFile VAR WritePathFile
  68.         
  69.         if open('OutFile',WritePathFile,'w') then
  70.         do
  71.             Title='Index of Directory ' getpath.pathpart ' page ' FileCount
  72.             call writeln('OutFile', '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">')
  73.             call writeln('OutFile', '<HTML>')
  74.             call writeln('OutFile', '<HEAD>')
  75.             call writeln('OutFile', '<TITLE>' Title '</TITLE>')
  76.           call writeln('OutFile', '</HEAD>')
  77.             call writeln('OutFile', '<BODY>')
  78.             call writeln('OutFile', '<H2 ALIGN="CENTER">' Title '</H2>')
  79.             call writeln('OutFile', '<TABLE WIDTH="100%" BORDER='TableBorder'>')
  80.         end    
  81.         else
  82.             exit
  83.     end
  84.  
  85.     /* <<<<<<<< Create the destination file name >>>>>>>> */
  86.     FILE_SPLIT FILE '"'srcfiles.files.l'"' STEM filesplit.
  87.  
  88.     filename=left(filesplit.filepart,index(filesplit.filepart,'.')-1)
  89.  
  90.     FILE_JOIN PATHPART '"'filesplit.pathpart'"',
  91.     FILEPART '"'TNPrefix||filename'.'TNExten'"' VAR 'destfile'
  92.  
  93.  
  94.     /* <<<<<<<< if thumb nail not yet generated make one >>>>>>>> */
  95.     if exists(destfile) ~=1 then
  96.     do
  97.         /* Open the file, do our own error check */
  98.         signal off error
  99.                  
  100.         OPEN FILE '"'srcfiles.files.l'"' FORCE
  101.     
  102.         if (rc~=0) then
  103.         do
  104.             /* deal with error */
  105.             nofile=1
  106.             signal on error
  107.                     
  108.         end    
  109.         else
  110.         do
  111.             signal on error
  112.  
  113.             /* Get and set size and depth info */
  114.             IMAGEINFO_GET STEM ImageInfo.
  115.             XPSize = SquareSize / ImageInfo.width
  116.             YPSize = SquareSize / ImageInfo.height
  117.             ImageDepth = ImageInfo.depth
  118.             
  119.             /* 8-bit colors max */
  120.             if ImageDepth>8 then
  121.                 ImageDepth=8
  122.  
  123.             NumCol=1
  124.  
  125.             do n=1 to ImageDepth
  126.                 NumCol=NumCol*2
  127.             end
  128.  
  129.             /* Fit image into square SquareSize X SquareSize */
  130.             if (XPSize < YPSize) then
  131.                 PSize = (XPSize * 100) + 0.5
  132.             else
  133.                 PSize = (YPSize * 100) + 0.5
  134.  
  135.             PSize=trunc(PSize,0) /* number must be integer */
  136.     
  137.             /* Rescale image , colour convertion neccessary for colour averaging */
  138.             COLOURS SIXTEENMILLION
  139.             SCALE  PSize PSize PERCENT METHOD "AVERAGE"
  140.             COLOURS NUMCOLOURS NumCol
  141.  
  142.             /* Save file */
  143.             SAVE FILE '"'destfile'"' FORMAT TNFormat ARGS '"'TNArgs'"' 
  144.                 
  145.             /* get new dimensions */
  146.             IMAGEINFO_GET STEM ImageInfo.
  147.  
  148.         end
  149.  
  150.     end    
  151.     else    /* load TN to get dimensions */
  152.     do
  153.         OPEN FILE '"'destfile'"' FORCE
  154.             
  155.         IMAGEINFO_GET STEM ImageInfo.            
  156.     end
  157.         
  158.     /* <<<<<<<< Write HTML for ThumbNail >>>>>>>>> */
  159.     if ColumnCount=1 then
  160.         call writeln('OutFile','<TR>')
  161.  
  162.     if(~nofile) then /* TN exists */
  163.         call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">',
  164. '<IMG SRC="'TNPrefix||filename'.'TNExten'" ALT="'filesplit.filepart'"',
  165. 'WIDTH="'ImageInfo.width'" HEIGHT="'ImageInfo.height'"></A>')
  166.     else    /* unable to create TN */
  167.     do
  168.         call writeln('OutFile','<TD><A HREF="'filesplit.filepart'">'||,
  169. filesplit.filepart'"</A>')
  170.         nofile=0
  171.     end
  172.             
  173.     /* <<<<<<<< Inc Column counter and test for end of rows etc >>>>>>>> */
  174.     ColumnCount=ColumnCount+1
  175.  
  176.     if ColumnCount > TableColumns then
  177.     do
  178.         call writeln('OutFile','</TR>')
  179.         ColumnCount=1
  180.         RowCount=RowCount+1
  181.     end
  182.         
  183.     /* <<<<<<<< if all rows complete, finish and close file >>>>>>>> */
  184.     if RowCount > TableRows then
  185.     do                
  186.         call writeln('OutFile', '</TABLE>')
  187.         call writeln('OutFile', '<CENTER><P>')
  188.             
  189.         /* if not first file add 'prev' link */
  190.         if FileCount=2 then
  191.             call writeln('OutFile', '<A HREF="'HTMLfile'.html">[Prev]</A>')
  192.         if FileCount>2 then
  193.             call writeln('OutFile', '<A HREF="'HTMLfile||FileCount-1'.html">[Prev]</A>')
  194.                 
  195.         if l < srcfiles.files.count then
  196.             call writeln('OutFile', '<A HREF="'HTMLfile||FileCount+1'.html">[Next]</A>')
  197.  
  198.         call writeln('OutFile', '</P></CENTER>')
  199.         call writeln('OutFile', '</BODY>')
  200.         call writeln('OutFile', '</HTML>')
  201.         call close('OutFile')    
  202.             
  203.         RowCount=1
  204.         FileCount=FileCount+1
  205.     end
  206.  
  207. end /* file loop */
  208.  
  209. /* <<<<<<<< Finish writing html and close file >>>>>>>> */
  210. if ColumnCount>1 then
  211.     call writeln('OutFile','</TR>')
  212.  
  213. call writeln('OutFile', '</TABLE>')    
  214. call writeln('OutFile', '<CENTER><P>')
  215.  
  216. /* if not first file add 'prev' link */
  217. if FileCount=2 then
  218.     call writeln('OutFile', '<A HREF="'HTMLfile'.html">[Prev]</A>')
  219. if FileCount>2 then
  220.     call writeln('OutFile', '<A HREF="'HTMLfile||FileCount-1'.html">[Prev]</A>')
  221.     
  222. call writeln('OutFile', '</P></CENTER>')
  223. call writeln('OutFile', '</BODY>')
  224. call writeln('OutFile', '</HTML>')
  225. call close('OutFile')
  226.  
  227.  
  228.  
  229. /* END PROGRAM ***************************************************/
  230.  
  231. exit
  232.  
  233. /* On ERROR */
  234.  
  235. ERROR:
  236.  
  237. /* If we get here, either an error occurred with the command's */
  238. /* execution or there was an error with the command itself. */
  239. /* In the former case, rc2 contains the error message and in */
  240. /* the latter, rc2 contains an error number. SIGL contains */
  241. /* the line number of the command which caused the jump */
  242. /* to ERROR: */
  243.  
  244. if datatype(rc2,'NUMERIC') == 1 then do
  245.    /* See if we can describe the error with a string */
  246.  
  247.    select
  248.       when rc2 == 103 then
  249.          err_string = "ERROR 103, "||,
  250.             "out of memory at line "||SIGL
  251.       when rc2 == 114 then
  252.          err_string = "ERROR 114, "||,
  253.             "bad command template at line "||SIGL
  254.       when rc2 == 115 then
  255.          err_string = "ERROR 115, "||,
  256.             "bad number for /N argument at line "||SIGL
  257.       when rc2 == 116 then
  258.          err_string = "ERROR 116, "||,
  259.             "required argument missing at line "||SIGL
  260.       when rc2 == 117 then
  261.          err_string = "ERROR 117, "||,
  262.             "value after keywork missing at line "||SIGL
  263.       when rc2 == 118 then
  264.          err_string = "ERROR 118, "||,
  265.             "wrong number of arguments at line "||SIGL
  266.       when rc2 == 119 then
  267.          err_string = "ERROR 119, "||,
  268.             "unmatched quotes at line "||SIGL
  269.       when rc2 == 120 then
  270.          err_string = "ERROR 120, "||,
  271.             "line too long at line "||SIGL
  272.       when rc2 == 236 then
  273.          err_string = "ERROR 236, "||,
  274.             "unknown command at line "||SIGL
  275.       otherwise
  276.          err_string = "ERROR "||rc2||", at line "||SIGL
  277.       end
  278.         end
  279. else if rc2 == 'RC2' then do
  280.    err_string = "ERROR in command at line "||SIGL
  281.    end
  282. else do
  283.         err_string = rc2||", line "||SIGL
  284.         end
  285.  
  286. request_message TEXT '"'err_string'"'
  287.  
  288. exit
  289.  
  290.